﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace HAZ.ConnectionFactory
{
    class DBConnectorMSSQL : IDBConnector
    {
        private SqlConnection sqlconn = null;
        private SqlCommand    sqlcmd  = null;

        public string ConnectionString { get; set; }

        public DBConnectorMSSQL(string connectionString)
        {
            this.ConnectionString = connectionString;

            sqlconn = new SqlConnection(this.ConnectionString);
        }

        #region IDBConnector Members
        public DataTable DataTableFromQuery(StringBuilder sQuery)
        {
            return this.DataTableFromQuery(sQuery.ToString());
        }
        public DataTable DataTableFromQuery(string        sQuery)
        {
            DataTable dtRet = new DataTable();
            sqlcmd = new SqlCommand(sQuery, sqlconn);

            //object o;
            //foreach (SqlParameter par in sqlcmd.Parameters)
            //    o = par.SqlDbType;
            new SqlDataAdapter(sqlcmd).Fill(dtRet);

            return dtRet;
        }

        public int ExecuteQuery(object value)
        {
            //TODO: conexao do sistema SQL.
            throw new NotImplementedException();
        }

        public DataTable Select(StringBuilder sQuery)
        {
            return this.Select(sQuery.ToString());
        }
        public DataTable Select(string        sQuery)
        {
            return DataTableFromQuery(sQuery);
        }

        public int Delete(params object[] filter)
        {
            return ExecuteQuery(null);
        }
        public int Update(object[] data, params object[] filter)
        {
            return ExecuteQuery(null);
        }
        public int Insert(object[] field, object[] data)
        {
            return ExecuteQuery(null);
        }
        #endregion
    }
}
